import 'package:flutter/material.dart';
import 'package:flutter_app/components/max_video_card.dart';
import 'package:flutter_app/components/root_page_head.dart';
import 'package:flutter_app/view/sub_page/article_page.dart';
import 'package:flutter_app/view/sub_page/head/view.dart';
import 'package:flutter_app/view/sub_page/max_video_page.dart';
import 'package:flutter_app/view/sub_page/recommend_page.dart';
import 'package:flutter_app/view/sub_page/search/view.dart';
import 'package:flutter_app/view/sub_page/singer_page.dart';
import 'package:flutter_app/view/sub_page/song_page.dart';
import 'package:flutter_app/view/sub_page/songs/view.dart';
import 'package:flutter_app/view/sub_page/video_page.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  HomePageState createState() => HomePageState();
}

const List<Tab> _tabs = [
  Tab(text: '歌曲'),
  Tab(text: '歌手'),
  Tab(text: '小视频'),
  Tab(text: '文章'),
  Tab(text: '推荐'),
  Tab(text: '视频'),
  Tab(text: '视频'),
  Tab(text: '微读'),
  Tab(text: '视频'),
];

final List<Widget> _tabContent = [
  SongsPage(),
  SingerPage(),
  VideoPage(),
  ArticlePage(),
  RecommendPage(),
  MaxVideoPage(),
  searchPage(),
  HeadPage(),
  Text('99'),
];

class HomePageState extends State<HomePage> with TickerProviderStateMixin {
  TabController _tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController =
        TabController(initialIndex: 0, length: _tabs.length, vsync: this);
//    _tabController.addListener(() {
//      _tabController.index
//    })
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: HeadPage(),
        bottom: TabBar(
          tabs: _tabs,
          controller: _tabController,
          isScrollable: true, //滚动
        ),
      ),
      body: TabBarView(
        children: _tabContent,
        controller: _tabController,
      ),
    );
  }
}
